<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>27.访问器伪造属性操作</title>
</head>

<body>
  <script>
    'use strict';
    let Lesson = {
      lists: [
        { name: "js", price: 100 },
        { name: "mysql", price: 212 },
        { name: "vue.js", price: 98 }
      ],
      // 这是个伪造属性，其实对象中没有total属性
      get total () {
        return this.lists.reduce((t, b) => t + b.price, 0);
      }
    };
  console.log(Lesson.total); //410
  Lesson.total = 30; //无效 属性是伪造的不能赋值,严格模式下会报错Uncaught TypeError: Cannot set property total of #<Object> which has only a getter
  console.log(Lesson.total); //410
  </script>
</body>

</html>